local ruilue_viewas = fk.CreateSkill{
  name = "swis__ruilue_viewas&",
  dynamic_desc = function (self, player, lang)
    local tail = ""
    if player:hasSkill("swis__ruilue", true) then tail = Fk:translate("swis__ruilue_ex") end
    return "swis__ruilue_viewas_inner:"..tail
  end
}

Fk:loadTranslationTable{
  ["swis__ruilue_viewas&"] = "睿略",
  [":swis__ruilue_viewas_inner"] = "你可以将一张扑克牌当与之花色、点数相同的基本牌{1}使用。",
  ["swis__ruilue_ex"] = "或普通锦囊牌",
}

local U = require "packages/utility/utility"

ruilue_viewas:addEffect("viewas", {
  anim_type = "special",
  pattern = tostring(Exppattern{ type = {"basic", "trick"} }),
  interaction = function (self, player)
    local all_names = Fk:getAllCardNames("bt")
    local names = player:getViewAsCardNames("swis__ruilue", all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function (self, player, to_select, selected)
    local name = self.interaction.data
    local card = Fk:getCardById(to_select)
    if #selected == 0 and card.trueName == "poker" and name then
      local map = Fk:currentRoom():getBanner("swis__ruilue_map")
      return table.contains(map[card.suit][card.number], name)
    end
  end,
  view_as = function (self, player, cards)
    local name = self.interaction.data
    if #cards == 0 or not name then return end
    local card = Fk:cloneCard(name)
    if card:isCommonTrick() and not player:hasSkill("swis__ruilue", true) then return end
    card.skillName = "swis__ruilue"
    card:addSubcards(cards)
    return card
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
  enabled_at_nullification = function (self, player, data)
    return player:hasSkill("swis__ruilue", true)
  end,
})

return ruilue_viewas